<HTML>
  <HEAD>
    <TITLE>threadpool Documentation</TITLE>
    <LINK HREF="threadpool.css" REL="stylesheet" TYPE="text/css">
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">

    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>

          <TD ALIGN="LEFT">
            <B>threadpool</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>

        </TR>
      </TABLE>
    </DIV>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
          <TD ALIGN="LEFT">
            <B>Reference</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="annotated.html">Class List</A> |
            <A CLASS="qindex" HREF="functions.html">Member Functions</A> |
            <A CLASS="qindex" HREF="namespacemembers.html">Typedefs</A> |
            <A CLASS="qindex" HREF="files.html">File List</A>
          </TD>
        </TR>
      </TABLE>
    </DIV>
<!-- Generated by Doxygen 1.4.6-NO -->
<h1>threadpool/future.hpp</h1><a href="a00028.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00016"></a>00016 <span class="preprocessor">#ifndef THREADPOOL_FUTURE_HPP_INCLUDED</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#define THREADPOOL_FUTURE_HPP_INCLUDED</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020   
<a name="l00021"></a>00021 <span class="preprocessor">#include "detail/future.hpp"</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;boost/utility/enable_if.hpp&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="comment">//#include "pool.hpp"</span>
<a name="l00025"></a>00025 <span class="comment">//#include &lt;boost/utility.hpp&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment">//#include &lt;boost/thread/mutex.hpp&gt;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="a00036.html">00030</a> <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>threadpool
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 
<a name="l00042"></a>00042 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Result&gt; 
<a name="l00043"></a><a class="code" href="a00014.html">00043</a> <span class="keyword">class </span><a class="code" href="a00014.html">future</a>
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045 <span class="keyword">private</span>:
<a name="l00046"></a>00046   shared_ptr&lt;detail::future_impl&lt;Result&gt; &gt; m_impl;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="keyword">public</span>:
<a name="l00049"></a><a class="code" href="a00014.html#d6fbc53d4a200a329a6b201bf86cf3fb">00049</a>     <span class="keyword">typedef</span> Result <span class="keyword">const</span> &amp; <a class="code" href="a00014.html#d6fbc53d4a200a329a6b201bf86cf3fb">result_type</a>; 
<a name="l00050"></a><a class="code" href="a00014.html#5c92a802f3c0d359df1adde078ce29dc">00050</a>     <span class="keyword">typedef</span> Result <a class="code" href="a00014.html#5c92a802f3c0d359df1adde078ce29dc">future_result_type</a>; 
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="keyword">public</span>:
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="a00014.html#a6dd25fb3fdf9aa08fc8e717ef82f16a">00055</a>   <a class="code" href="a00014.html#a6dd25fb3fdf9aa08fc8e717ef82f16a">future</a>()
<a name="l00056"></a>00056   : m_impl(new detail::future_impl&lt;<a class="code" href="a00014.html#5c92a802f3c0d359df1adde078ce29dc">future_result_type</a>&gt;()) <span class="comment">// TODO remove this</span>
<a name="l00057"></a>00057   {
<a name="l00058"></a>00058   }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060   <span class="comment">// only for internal usage</span>
<a name="l00061"></a><a class="code" href="a00014.html#a5f3763bb5744f0e9c93511320a8cb58">00061</a>   <a class="code" href="a00014.html#a6dd25fb3fdf9aa08fc8e717ef82f16a">future</a>(shared_ptr&lt;detail::future_impl&lt;Result&gt; &gt; <span class="keyword">const</span> &amp; impl)
<a name="l00062"></a>00062   : m_impl(impl)
<a name="l00063"></a>00063   {
<a name="l00064"></a>00064   }
<a name="l00065"></a>00065 
<a name="l00066"></a><a class="code" href="a00014.html#8dbeb39974d24cc91e82f5d83d4ac8ba">00066</a>   <span class="keywordtype">bool</span> <a class="code" href="a00014.html#8dbeb39974d24cc91e82f5d83d4ac8ba">ready</a>()<span class="keyword"> const</span>
<a name="l00067"></a>00067 <span class="keyword">  </span>{
<a name="l00068"></a>00068     <span class="keywordflow">return</span> m_impl-&gt;ready();
<a name="l00069"></a>00069   }
<a name="l00070"></a>00070 
<a name="l00071"></a><a class="code" href="a00014.html#baff292f21d3fb305426735e0347e2a0">00071</a>   <span class="keywordtype">void</span> <a class="code" href="a00014.html#baff292f21d3fb305426735e0347e2a0">wait</a>()<span class="keyword"> const</span>
<a name="l00072"></a>00072 <span class="keyword">  </span>{
<a name="l00073"></a>00073     m_impl-&gt;wait();
<a name="l00074"></a>00074   }
<a name="l00075"></a>00075 
<a name="l00076"></a><a class="code" href="a00014.html#19db862f732df1b8e49da5bf2b0cebce">00076</a>   <span class="keywordtype">bool</span> <a class="code" href="a00014.html#19db862f732df1b8e49da5bf2b0cebce">timed_wait</a>(boost::xtime <span class="keyword">const</span> &amp; timestamp)<span class="keyword"> const</span>
<a name="l00077"></a>00077 <span class="keyword">  </span>{
<a name="l00078"></a>00078     <span class="keywordflow">return</span> m_impl-&gt;timed_wait(timestamp);
<a name="l00079"></a>00079   }
<a name="l00080"></a>00080 
<a name="l00081"></a><a class="code" href="a00014.html#5a744da9ad9746ade1f64f93eda13249">00081</a>    <a class="code" href="a00014.html#d6fbc53d4a200a329a6b201bf86cf3fb">result_type</a> <a class="code" href="a00014.html#5a744da9ad9746ade1f64f93eda13249">operator()</a>() <span class="comment">// throw( thread::cancelation_exception, ... )</span>
<a name="l00082"></a>00082    {
<a name="l00083"></a>00083      <span class="keywordflow">return</span> (*m_impl)();
<a name="l00084"></a>00084    }
<a name="l00085"></a>00085 
<a name="l00086"></a><a class="code" href="a00014.html#7a4c96e26df00c208c042f8bc451aae5">00086</a>    <a class="code" href="a00014.html#d6fbc53d4a200a329a6b201bf86cf3fb">result_type</a> <a class="code" href="a00014.html#7a4c96e26df00c208c042f8bc451aae5">get</a>() <span class="comment">// throw( thread::cancelation_exception, ... )</span>
<a name="l00087"></a>00087    {
<a name="l00088"></a>00088      <span class="keywordflow">return</span> (*m_impl)();
<a name="l00089"></a>00089    }
<a name="l00090"></a>00090 
<a name="l00091"></a><a class="code" href="a00014.html#1fc4f71950bae7ed2da03a1351632308">00091</a>    <span class="keywordtype">bool</span> <a class="code" href="a00014.html#1fc4f71950bae7ed2da03a1351632308">cancel</a>()
<a name="l00092"></a>00092    {
<a name="l00093"></a>00093      <span class="keywordflow">return</span> m_impl-&gt;cancel();
<a name="l00094"></a>00094    }
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="a00014.html#5e69be7f923e55752472b8d8e03eac29">00096</a>    <span class="keywordtype">bool</span> <a class="code" href="a00014.html#5e69be7f923e55752472b8d8e03eac29">is_cancelled</a>()<span class="keyword"> const</span>
<a name="l00097"></a>00097 <span class="keyword">   </span>{
<a name="l00098"></a>00098      <span class="keywordflow">return</span> m_impl-&gt;is_cancelled();
<a name="l00099"></a>00099    }
<a name="l00100"></a>00100 };
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 
<a name="l00103"></a>00103 
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Pool, <span class="keyword">class</span> Function&gt;
<a name="l00107"></a>00107 <span class="keyword">typename</span> disable_if &lt; 
<a name="l00108"></a>00108   is_void&lt; typename result_of&lt; Function() &gt;::type &gt;,
<a name="l00109"></a>00109   future&lt; typename result_of&lt; Function() &gt;::type &gt;
<a name="l00110"></a>00110 &gt;::type
<a name="l00111"></a><a class="code" href="a00036.html#a3a3ab4f72886455dbdf1f89da8cf2de">00111</a> <a class="code" href="a00036.html#a3a3ab4f72886455dbdf1f89da8cf2de">schedule</a>(Pool&amp; <a class="code" href="a00024.html">pool</a>, <span class="keyword">const</span> Function&amp; task)
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113   <span class="keyword">typedef</span> <span class="keyword">typename</span> result_of&lt; Function() &gt;::type future_result_type;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115   <span class="comment">// create future impl and future</span>
<a name="l00116"></a>00116   shared_ptr&lt;detail::future_impl&lt;future_result_type&gt; &gt; impl(<span class="keyword">new</span> detail::future_impl&lt;future_result_type&gt;);
<a name="l00117"></a>00117   future &lt;future_result_type&gt; res(impl);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119   <span class="comment">// schedule future impl</span>
<a name="l00120"></a>00120   pool.schedule(detail::future_impl_task_func&lt;detail::future_impl, Function&gt;(task, impl));
<a name="l00121"></a>00121 
<a name="l00122"></a>00122   <span class="comment">// return future</span>
<a name="l00123"></a>00123   <span class="keywordflow">return</span> res;
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 <span class="comment">/*</span>
<a name="l00126"></a>00126 <span class="comment"> TODO</span>
<a name="l00127"></a>00127 <span class="comment">  if(pool-&gt;schedule(bind(&amp;Future::run, future)))</span>
<a name="l00128"></a>00128 <span class="comment">  {</span>
<a name="l00129"></a>00129 <span class="comment">    return future;</span>
<a name="l00130"></a>00130 <span class="comment">  }</span>
<a name="l00131"></a>00131 <span class="comment">  else</span>
<a name="l00132"></a>00132 <span class="comment">  {</span>
<a name="l00133"></a>00133 <span class="comment">    // construct empty future</span>
<a name="l00134"></a>00134 <span class="comment">    return error_future;</span>
<a name="l00135"></a>00135 <span class="comment">  }</span>
<a name="l00136"></a>00136 <span class="comment">  */</span>
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 } } <span class="comment">// namespace boost::threadpool</span>
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 <span class="preprocessor">#endif // THREADPOOL_FUTURE_HPP_INCLUDED</span>
<a name="l00144"></a>00144 <span class="preprocessor"></span>
</pre></div>    <BR>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
		  <TD CLASS="tiny" ALIGN="LEFT">Copyright &copy 2005-2007 Philipp Henkel</TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>
        </TR>       
      </TABLE>
    </DIV>  
  </BODY>
</HTML>
